{
语法百题 解题报告：
 http://git.oschina.net/et0662/sznoi-grammar/ 
}

var
	a:array of array of longint;
	m,n,i,j:integer;
	count:longint=0;
begin
	readln(m,n);
	setlength(a,m+1,n+1);
	for i:=1 to m do
	for j:=1 to n do
		read(a[i,j]);
	for i:=1 to m do
	for j:=1 to n do
		if(a[i,j]<>0)then
		inc(count);
	writeln(count);
	for i:=1 to m do
	for j:=1 to n do
		if(a[i,j]<>0)then
		writeln(i,' ',j,' ',a[i,j]);
end.
